import { defineEventHandler } from 'h3'
import records from '~/server/data/records.json'
import type { Record } from '~/types/record'

export default defineEventHandler((event) => {
  const songId = Number(event.context.params?.id)

  if (!songId) {
    throw createError({
      statusCode: 400,
      statusMessage: 'Song ID is required',
    })
  }

  const songRecords = (records as Record[]).filter(
    (record) => record.song_id === songId
  )

  return songRecords
})